package com.gcl.rabbitmq;

import com.gcl.rabbitmq.utils.RabbitmqUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
import java.util.concurrent.TimeoutException;

public class Producer {

    private static final String QUEUE_NAME = "Hello Word";


    public static void main(String[] args) throws IOException, TimeoutException {

        Channel channel = RabbitmqUtils.getChannel();

        // 队列持久化
        channel.queueDeclare(QUEUE_NAME,true,false,false,null);


        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String msg = scanner.next();
            // 信道中的消息持久化 MessageProperties.PERSISTENT_TEXT_PLAIN
            channel.basicPublish("",QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN,msg.getBytes(StandardCharsets.UTF_8));
        }



        // 在C2等待的过程中关闭C2，未被C2接受的轮询信息会被发送给C1，因为我们使用了手动应答的方式吗，确保的消息的不丢失

    }
}
